<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
// checks to see if password session is set
// if not redirects to ../admin/
if($_SESSION['loggedIn'] == 0 && !isset($adminPage)){
include('auth.inc.php');
}




// approve
if (isset($_POST['tagchanges'])) {
$tagresult = mysql_query("SELECT * FROM affiliSt_cloud ORDER BY searchPhrase ASC");
$tagrow = mysql_fetch_array($tagresult);

	do {
		if ($_POST['delete-'.$tagrow['searchPhrase']] == 1) {
		$phrasedelete = $tagrow['searchPhrase'];
		mysql_query("DELETE FROM affiliSt_cloud WHERE searchPhrase = '$phrasedelete'");
		} else {
			if ($_POST[$tagrow['searchPhrase']] == 1) {
			$setapprove = 1;
			$phraseinsert = $tagrow['searchPhrase'];
			} else {
			$setapprove = 0;
			$phraseinsert = $tagrow['searchPhrase'];
			}
		mysql_query("UPDATE affiliSt_cloud SET approve = '$setapprove' WHERE searchPhrase = '$phraseinsert'");
		}
	} while ($tagrow = mysql_fetch_array($tagresult));
	
}

?>

<?php
// error report
if (isset($_POST['tagchanges'])) {
echo '<fieldset><strong style="color:green">Search Tags Updated</strong></fieldset>';
}
?>

<script type="text/javascript">
function selectAllBoxes(formselect, checkgroup, totalboxes) {
	if (formselect.checked == true) {
		for (i=0;i<totalboxes;i++) {
		document.getElementById(checkgroup+i).checked = true;
		}
	} else {
		for (i=0;i<totalboxes;i++) {
		document.getElementById(checkgroup+i).checked = false;
		}
	}
}
</script>



<fieldset>
<legend>Manage Search Tags</legend>
<form action="index.php?ad=st" method="post" name="searchTags">
<table cellpadding="4" cellspacing="0" border="0" width="100%">
<tr>
	<th align="left">Search Term</th>
	<th align="left">Total Searches</th>
	<th align="right">Approve Tag?</th>
	<th align="right">Delete?</th>
</tr>
<tr>
<td align="right" valign="top" colspan="3" style="background-color:#eeeeee;">
Select/Unselect All <input name="selectAll" type="checkbox" onclick="selectAllBoxes(this, 'tagcheckbox', 100);" />
</td>
<td align="right" style="background-color:#eeeeee;"><input name="selectDeleteAll" type="checkbox" onclick="selectAllBoxes(this, 'deletecheckbox', 100);" /></td>
</tr>
<?php
$listtags = mysql_query("SELECT * FROM affiliSt_cloud ORDER BY searchPhraseCount DESC LIMIT 0,100");
$tagrow = mysql_fetch_assoc($listtags);
$tagcount = 0;
if ($tagrow['searchPhraseID'] != NULL) {
	do {
		if ($tagrow['approve'] == 1) {
		$checked = 'checked="checked"';
		} else {
		$checked = '';
		}
		echo 
		'<tr><td>'.str_replace("-", "&nbsp;", $tagrow['searchPhrase']).
		'</td><td align="center">('.$tagrow['searchPhraseCount'].')
		</td><td align="right"><input name="'.$tagrow['searchPhrase'].'" type="checkbox" '.$checked.' value="1" id="tagcheckbox'.$tagcount.'" />
		</td><td align="right"><input name="delete-'.$tagrow['searchPhrase'].'" type="checkbox" value="1" id="deletecheckbox'.$tagcount.'" />
		</td></tr>';
		$tagcount++;
	} while ($tagrow = mysql_fetch_assoc($listtags));

?>
</table>
<input name="tagchanges" type="submit" value="Update Search Tags" />
<?php } ?>
</form>
</fieldset>